import * as API from '../../api'
export default {
  namespaced: true,
  state: {
    songdetails: {},
    lyric: '',
    songComment: [],
    songsLike: [],
    songId: 1483302307,
    songURL: ''
  },
  getters: {},
  actions: {
    async getSinglePlay({ commit }, { ids }) {
      const songs = await API.singleplay.reqGetSinglePlay(ids)
      const songdetails = songs.songs[0]
      commit('GET_SINGLE_PLAY', songdetails)
    },
    async getLyric({ commit }, { ids }) {
      const songlyric = await API.singleplay.reqGetLyric(ids)
      const lyric = songlyric.lrc.lyric
      commit('GET_LYRIC', lyric)
    },
    async getChat({ commit }, { ids }) {
      const songChat = await API.singleplay.reqGetChat(ids)
      const songComment = songChat.comments
      commit('GET_CHAT', songComment)
    },
    async getSongLike({ commit }, { ids }) {
      const songs = await API.singleplay.reqGetSongLike(ids)
      const songsLike = songs.songs
      commit('GET_SONG_LIKE', songsLike)
    },
    async getSongURL({ commit }, { ids }) {
      const result = await API.singleplay.reqGetSongURL(ids)
      const songURL = result.data[0].url
      commit('GET_SONG_URL', songURL)
    }
  },
  mutations: {
    GET_SINGLE_PLAY(state, songdetails) {
      state.songdetails = songdetails
    },
    GET_LYRIC(state, lyric) {
      state.lyric = lyric
    },
    GET_CHAT(state, songComment) {
      state.songComment = songComment
    },
    GET_SONG_LIKE(state, songsLike) {
      state.songsLike = songsLike
    },
    SET_SONG_ID(state, songId) {
      state.songId = songId
    },
    GET_SONG_URL(state, songURL) {
      state.songURL = songURL
    }
  }
}
